package com.ruoyi.keep.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.constant.CommonConstant;
import org.springframework.security.access.method.P;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.keep.domain.Reservation;
import com.ruoyi.keep.service.IReservationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 团课预约管理Controller
 * 
 * @author wangziyang
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/keep/reservation")
public class ReservationController extends BaseController
{
    @Autowired
    private IReservationService reservationService;

    /**
     * 查询团课预约管理列表
     */
    @PreAuthorize("@ss.hasPermi('keep:reservation:list')")
    @GetMapping("/list")
    public TableDataInfo list(Reservation reservation)
    {
        startPage();
        List<Reservation> list = reservationService.selectReservationList(reservation);
        return getDataTable(list);
    }

    /**
     * 导出团课预约管理列表
     */
    @PreAuthorize("@ss.hasPermi('keep:reservation:export')")
    @Log(title = "团课预约管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Reservation reservation)
    {
        List<Reservation> list = reservationService.selectReservationList(reservation);
        ExcelUtil<Reservation> util = new ExcelUtil<Reservation>(Reservation.class);
        util.exportExcel(response, list, "团课预约管理数据");
    }

    /**
     * 获取团课预约管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('keep:reservation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(reservationService.selectReservationById(id));
    }

    /**
     * 新增团课预约管理
     */
    @PreAuthorize("@ss.hasPermi('keep:reservation:add')")
    @Log(title = "团课预约管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Reservation reservation)
    {
        return toAjax(reservationService.insertReservation(reservation));
    }

    /**
     * 修改团课预约管理
     */
    @PreAuthorize("@ss.hasPermi('keep:reservation:edit')")
    @Log(title = "团课预约管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Reservation reservation)
    {
        return toAjax(reservationService.updateReservation(reservation));
    }

    /**
     * 删除团课预约管理
     */
    @PreAuthorize("@ss.hasPermi('keep:reservation:remove')")
    @Log(title = "团课预约管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(reservationService.deleteReservationByIds(ids));
    }
//    团课预约查询--全部
    @GetMapping("/teamReservationList")
    public AjaxResult teamReservationList(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT)Integer pageNum,
                                          @RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT)Integer pageSize,
                                          Reservation reservation){
        return success(reservationService.selectTeamReservationList(pageNum,pageSize,reservation));
    }
//    同意退款
    @PostMapping("/updateReservationOrderStatus/{id}")
    public AjaxResult updateReservationOrderStatus(@PathVariable Long id){
        return toAjax(reservationService.updateReservationOrderStatus(id));
    }
    /*
    * 不同意退款
    * */
    @PostMapping("/updateReservationOrderStatusRefuse/{id}")
    public AjaxResult updateReservationOrderStatusRefuse(@PathVariable Long id){
        return toAjax(reservationService.updateReservationOrderStatusRefuse(id));
    }

    //私课预约查询--全部
    @GetMapping("/personalReservationList")
    public TableDataInfo personalReservationList(Reservation reservation){
        startPage();
        return getDataTable(reservationService.selectPersonalReservationList(reservation));
    }
    //私课预约查询--根据用户id查询
    @GetMapping("/personalReservationListByUserId")
    public TableDataInfo personalReservationListByUserId(Reservation reservation){
        return getDataTable(reservationService.selectPersonalReservationListByUserId(reservation));
    }
//    取消预约--私教和团课都可以
    @PutMapping("/updateReservationStatus")
    public AjaxResult updateReservationStatus(@RequestBody Reservation reservation){
        return toAjax(reservationService.updateReservationStatus(reservation));
    }
//    预约签到
    @PutMapping("/updateReservationStatusSign")
    public AjaxResult updateSignReservationStatus(@RequestBody Reservation reservation){
        return toAjax(reservationService.updateSignReservationStatus(reservation));
    }
//    团课预约查询--根据用户id查询
    @GetMapping("/selectTeamReservationListByUserId")
    public TableDataInfo selectTeamReservationListByUserId(Reservation reservation){
        return getDataTable(reservationService.selectTeamReservationListByUserId(reservation));
    }

}
